/*
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package org.xptracker.util;

import junit.framework.TestCase;

public class SideBySideRendererTest extends TestCase {
  public void testPrintDiff() throws Exception {
    SideBySideRenderer<String> renderer = new SideBySideRenderer<String>(DiffTest.DIFF);
    final StringBuffer results = new StringBuffer();

    renderer.render(new SideBySideRenderer.Printer<String>() {
      public void printHeader() {
        results.append("-- Starting Diff --\n");
      }

      public void printFooter() {
        results.append("-- Finishing Diff --\n");
      }

      public void printLine(boolean common, String left, String right) {
        if (common) {
          results.append(left).append('\n');
        } else {
          results.append(left == null ? "-" : left).append(" | ").append(right == null ? "-" : right).append('\n');
        }
      }
    });

    assertEquals("-- Starting Diff --\n" +
        "common1\n" +
        "common2\n" +
        "common3\n" +
        "diff1Left | diff1Right\n" +
        "diff2Left | diff2Right\n" +
        "- | diff3Right\n" +
        "common4\n" +
        "common5\n" +
        "diff4Left | diff4Right\n" +
        "diff5Left | diff5Right\n" +
        "common6\n" +
        "- | diff6Right\n" +
        "common7\n" +
        "diff7Left | -\n" +
        "common8\n" +
        "- | diff8Right\n" +
        "-- Finishing Diff --\n", results.toString());
  }
}
